gtkimcontextsimple.c: Use X11_DATA_PREFIX only on X11/Wayland
authorChun-wei Fan <fanchunwei@src.gnome.org>
Thu, 12 Nov 2015 12:20:36 +0000 (20:20 +0800)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 13 Nov 2015 12:39:54 +0000 (07:39 -0500)
Only use the hard-coded build-time path given by X11_PREFIX on X11 and
Wayland where a X11 package is normally available.  On other platforms,
get the datadir of the running system and mimic the behavior by
constructing the path dynamically.  This avoids hardcoding the path for
searching for compose tables where we want to have relocatability.

This fixes the build on Windows/MSVC as well, where we don't normally have
any X11 packages available.

https://bugzilla.gnome.org/show_bug.cgi?id=757984

gtk/gtkimcontextsimple.c

index 82c5221e64442d5edf5a2ec31fcf98169913c55a..41199f628a0f924d076bf1b3fde857838d66c234 100644 (file)
@@ -61,9 +61,6 @@
  * G WITH CEDILLA, i.e. ģ.
  */
 
-
-#define X11_DATADIR X11_DATA_PREFIX "/share/X11/locale"
-
 struct _GtkIMContextSimplePrivate
 {
   guint16        compose_buffer[GTK_MAX_COMPOSE_LEN + 1];
@@ -133,6 +130,23 @@ gtk_im_context_simple_class_init (GtkIMContextSimpleClass *class)
   gobject_class->finalize = gtk_im_context_simple_finalize;
 }
 
+static gchar*
+get_x11_compose_file_dir (void)
+{
+  gchar* compose_file_dir;
+  gchar* datadir = NULL;
+
+#if defined (GDK_WINDOWING_X11) || defined (GDK_WINDOWING_WAYLAND)
+  compose_file_dir = g_strdup (X11_DATA_PREFIX "/share/X11/locale");
+#else
+  datadir = g_strdup (_gtk_get_datadir ());
+  compose_file_dir = g_build_filename (datadir, "X11", "locale", NULL);
+  g_free (datadir);
+#endif
+
+  return compose_file_dir;
+}
+
 static void
 gtk_im_context_simple_init_compose_table (GtkIMContextSimple *im_context_simple)
 {
@@ -143,6 +157,7 @@ gtk_im_context_simple_init_compose_table (GtkIMContextSimple *im_context_simple)
   gchar **lang = NULL;
   gchar * const sys_langs[] = { "el_gr", "fi_fi", "pt_br", NULL };
   gchar * const *sys_lang = NULL;
+  gchar *x11_compose_file_dir = get_x11_compose_file_dir ();
 
   path = g_build_filename (g_get_user_config_dir (), "gtk-3.0", "Compose", NULL);
   if (g_file_test (path, G_FILE_TEST_EXISTS))
@@ -189,7 +204,7 @@ gtk_im_context_simple_init_compose_table (GtkIMContextSimple *im_context_simple)
         {
           if (g_ascii_strncasecmp (*lang, *sys_lang, strlen (*sys_lang)) == 0)
             {
-              path = g_build_filename (X11_DATADIR, *lang, "Compose", NULL);
+              path = g_build_filename (x11_compose_file_dir, *lang, "Compose", NULL);
               break;
             }
         }
@@ -203,6 +218,7 @@ gtk_im_context_simple_init_compose_table (GtkIMContextSimple *im_context_simple)
       path = NULL;
     }
 
+  g_free (x11_compose_file_dir);
   g_strfreev (langs);
 
   if (path != NULL)